//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package tankgame;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Vector;
import javax.swing.JPanel;

public class MyPanel extends JPanel implements KeyListener {
    Hero hero = null;
    Vector<EnemyTank> enemyTanks = new Vector();
    int enemyTankSize = 3;

    public MyPanel() {
        this.hero = new Hero(100, 100);

        for(int i = 0; i < this.enemyTankSize; ++i) {
            EnemyTank enemyTank = new EnemyTank(100 * (i + 1), 0);
            enemyTank.setDirect(2);
            this.enemyTanks.add(enemyTank);
        }

    }

    public void paint(Graphics g) {
        super.paint(g);
        g.fillRect(0, 0, 1000, 750);
        this.drawTank(this.hero.getX(), this.hero.getY(), g, this.hero.getDirect(), 1);

        for(int i = 0; i < this.enemyTanks.size(); ++i) {
            EnemyTank enemyTank = (EnemyTank)this.enemyTanks.get(i);
            this.drawTank(enemyTank.getX(), enemyTank.getY(), g, enemyTank.getDirect(), 0);
        }

    }

    public void drawTank(int x, int y, Graphics g, int direct, int type) {
        switch(type) {
            case 0:
                g.setColor(Color.BLUE);
                break;
            case 1:
                g.setColor(Color.ORANGE);
        }

        switch(direct) {
            case 0:
                g.fill3DRect(x, y, 10, 60, false);
                g.fill3DRect(x + 30, y, 10, 60, false);
                g.fill3DRect(x + 10, y + 10, 20, 40, false);
                g.fillOval(x + 10, y + 20, 20, 20);
                g.drawLine(x + 20, y + 30, x + 20, y);
                break;
            case 1:
                g.fill3DRect(x, y, 60, 10, false);
                g.fill3DRect(x, y + 30, 60, 10, false);
                g.fill3DRect(x + 10, y + 10, 40, 20, false);
                g.fillOval(x + 20, y + 10, 20, 20);
                g.drawLine(x + 30, y + 20, x + 60, y + 20);
                break;
            case 2:
                g.fill3DRect(x, y, 10, 60, false);
                g.fill3DRect(x + 30, y, 10, 60, false);
                g.fill3DRect(x + 10, y + 10, 20, 40, false);
                g.fillOval(x + 10, y + 20, 20, 20);
                g.drawLine(x + 20, y + 30, x + 20, y + 60);
                break;
            case 3:
                g.fill3DRect(x, y, 60, 10, false);
                g.fill3DRect(x, y + 30, 60, 10, false);
                g.fill3DRect(x + 10, y + 10, 40, 20, false);
                g.fillOval(x + 20, y + 10, 20, 20);
                g.drawLine(x + 30, y + 20, x, y + 20);
                break;
            default:
                System.out.println("暂时没有处理");
        }

    }

    public void keyTyped(KeyEvent e) {
    }

    public void keyPressed(KeyEvent e) {
        if (e.getKeyCode() == 40) {
            this.hero.moveDown();
            this.hero.setDirect(2);
        } else if (e.getKeyCode() == 38) {
            this.hero.moveUp();
            this.hero.setDirect(0);
        } else if (e.getKeyCode() == 37) {
            this.hero.setDirect(3);
            this.hero.setDirect(3);
        } else if (e.getKeyCode() == 39) {
            this.hero.moveRight();
            this.hero.setDirect(1);
        }

        this.repaint();
    }

    public void keyReleased(KeyEvent e) {
    }
}
